$(function(){
	//全局分布
	$(".main").css({ //右侧布的高度，相当于左侧高度
		height: $("#sidebar-nav").outerHeight()
	});	
	
    // admin收缩展开
    $('.admin-item>a').on('click',function(){
        if (!$('.admin').hasClass('admin-mini')) {
            if ($(this).next().css('display') == "none") {
                //展开未展开
                $('.admin-item').children('ul').slideUp(300);
                $(this).next('ul').slideDown(300);
                $(this).parent('li').addClass('admin-show').siblings('li').removeClass('admin-show');
            }else{
                //收缩已展开
                $(this).next('ul').slideUp(300);
                $('.admin-item.admin-show').removeClass('admin-show');
            }
        }
    });
    //admin-mini切换
    $('#mini').on('click',function(){
        if (!$('.admin').hasClass('admin-mini')) {
            $('.admin-item.admin-show').removeClass('admin-show');
            $('.admin-item').children('ul').removeAttr('style');
            $('.admin').addClass('admin-mini');
        }else{
            $('.admin').removeClass('admin-mini');
        }
    });
    
	$(".btn-toggle-mx").click(function () { //logo旁的开关动画
		$(this).toggleClass("transmx");
	});
	
	//左侧a链接直接导入右侧iframe
	$(".iframe_link").on("click", function () {
		debugger;
		var url = $(this).attr("href");
		$(".iframe_mx").attr("src", url);
		return false;
	});
	
	//左侧菜单栏伸展、收缩
	$('.btn-toggle-fullwidth').on('click', function () {
		if (!$('body').hasClass('layout-fullwidth')) {
			$('body').addClass('layout-fullwidth');

		} else {
			$('body').removeClass('layout-fullwidth');
			$('body').removeClass('layout-default'); // also remove default behaviour if set
		}
	});

	//天气预报弹窗
	$("[rel=drevil]").popover({
		trigger:'manual',
		placement : 'bottom', //placement of the popover. also can use top, bottom, left or right
		title : '<div style="text-align:center;color:#5bc0de; font-size:20px;">天气详情</div>', //this is the top title bar of the popover. add some basic css
		html: 'true', //needed to show html of course
		content :'<div id="weatherShow" style="height:250px;width:300px;"></div>', 
		animation: false
		}).on("mouseenter", function () {
			$.ajax({
			    url: "/weather/cityName/成都",
			    data: null,
			    type: "get",
			    dataType: "json",
			    success: function(result) {
			    	if(result.status=="1000"){
			    		data=result.data;
			    		today=data.forecast[0];
			    		aqi=data.aqi==null?'无':data.aqi
			    		weather=
			    				'<div style="height:100%;border:1px solid #5bc0de;border-radius:10px;">'+
				    			'<p>&nbsp;&nbsp;所在城市：<span style="color:#5bc0de;">'+data.city+'</span></p>'+
				    			'<p>&nbsp;&nbsp;当前温度：<span style="color:#5bc0de;">'+data.wendu+'℃'+'</span></p>'+
			                	'<p>&nbsp;&nbsp;天气类型：<span style="color:#5bc0de;">'+today.type+'</span></p>'+
			                	'<p>&nbsp;&nbsp;最高温度：<span style="color:#5bc0de;">'+today.high+'</span></p>'+
			                	'<p>&nbsp;&nbsp;最低温度：<span style="color:#5bc0de;">'+today.low+'</span></p>'+
			                	'<p>&nbsp;&nbsp;当前风向：<span style="color:#5bc0de;">'+today.fengxiang+'</span></p>'+
			                	'<p>&nbsp;&nbsp;空气质量：<span style="color:#5bc0de;">'+aqi+'</span></p>'+
			                	'<p style="color:red;">温馨提示：<span style="color:#5bc0de;">'+data.ganmao+'</span></p>'
			                	'</div>'+
			    		$("#weatherShow").html(weather)
			    	}else{
			    		$("#weatherShow").html('<div style="height:100%;border:1px solid #5bc0de;border-radius:10px;">天气查询失败</div>')
			    	}
			    }
			});
			var _this = this;
			$(this).popover("show");
			$(this).siblings(".popover").on("mouseleave", function () {
				$(_this).popover('hide');
			});
		}).on("mouseleave", function () {
			var _this = this;
			setTimeout(function () {
				if (!$(".popover:hover").length) {
					$(_this).popover("hide")
				}
			}, 100);
		});
/***********************************************导航栏和tab标签页的联动*************************************************/
    // 刷新按钮
    $('#refreshBtn').on('click', function() {
    	debugger;
    	var currentId = $('.page-tabs-content').find('.active').attr('data-id');
    	var target = $('.J_iframe[data-id="' + currentId + '"]');
        var url = target.attr('src');
        target.attr('src', url).ready();
    });
	});